package com.smedi.ismedi.inmail.core.port.adapter.restful;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smedi.ismedi.inmail.api.dto.request.LoginLogUserStaticsExportRequest;
import com.smedi.ismedi.inmail.api.dto.request.LoginLogUserStaticsPageRequest;
import com.smedi.ismedi.inmail.api.dto.response.LoginLogUserStaticsResponse;
import com.smedi.ismedi.inmail.api.feign.RemoteLoginLogUserStaticsFeignApi;
import com.smedi.ismedi.inmail.core.application.command.LoginLogUserStaticsListCommand;
import com.smedi.ismedi.inmail.core.application.command.LoginLogUserStaticsPageCommand;
import com.smedi.ismedi.inmail.core.application.query.LoginLogUserStaticsQueryService;
import com.smedi.ismedi.inmail.core.application.service.LoginLogUserStaticsApplicationService;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.LoginLogUserStatics;
import com.smedi.ismedi.inmail.core.port.adapter.convert.AdapterConverter;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 通知公告Controller
 *
 * @author jiangqinxuan
 * @date 2021/07/26
 */
@AllArgsConstructor
@RestController
public class LoginLogUserStaticsController implements RemoteLoginLogUserStaticsFeignApi {
    private final LoginLogUserStaticsQueryService loginLogUserStaticsQueryService;

    private final LoginLogUserStaticsApplicationService loginLogUserStaticsApplicationService;

    private final AdapterConverter adapterConverter;

    @Override
    public ResponseData<PaginationData<LoginLogUserStaticsResponse>> page(LoginLogUserStaticsPageRequest loginLogUserStaticsPageRequest) {
        LoginLogUserStaticsPageCommand loginLogUserStaticsPageCommand = adapterConverter.loginLogUserStaticsPageRequestToLoginLogUserStaticsPageCommand(loginLogUserStaticsPageRequest);
        Page<LoginLogUserStatics> loginLogUserStaticsPage = loginLogUserStaticsQueryService.page(loginLogUserStaticsPageCommand);
        PaginationData<LoginLogUserStaticsResponse> loginLogUserStaticsResponsePaginationData = adapterConverter.loginLogUserStaticsPageToLoginLogUserStaticsResponsePaginationData(loginLogUserStaticsPage);
        return new ResponseData<>().success(loginLogUserStaticsResponsePaginationData);
    }

    @Override
    public ResponseData<Boolean> statics() {
        loginLogUserStaticsApplicationService.statics();
        return new ResponseData<>().success(true);
    }

    @Override
    public ResponseData<String> export(LoginLogUserStaticsExportRequest loginLogUserStaticsExportRequest) {
        LoginLogUserStaticsListCommand loginLogUserStaticsListCommand = adapterConverter.loginLogUserStaticsExportRequestToLoginLogUserStaticsListCommand(loginLogUserStaticsExportRequest);
        List<LoginLogUserStatics> loginLogUserStatics = loginLogUserStaticsQueryService.list(loginLogUserStaticsListCommand);
        return new ResponseData<>().success(loginLogUserStaticsApplicationService.export(loginLogUserStatics));
    }
}
